package com.xiangyu.demo.configuration.jms;

import com.xiangyu.demo.bean.UserInfo;
import com.xiangyu.demo.configuration.JmsConfig;
import org.springframework.beans.BeanUtils;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;

/**
 * java类简单作用描述
 *
 * @ProjectName: springboot-demo
 * @Package: com.xiangyu.demo.configuration.jms
 * @Description: java类作用描述
 * @Author: 向羽
 * @CreateDate: 2018/1/29 10:39
 * @UpdateUser: 向羽
 * @UpdateDate: 2018/1/29 10:39
 * @UpdateRemark: The modified content
 * @Version: 2.0
 */
@Component
public class Consumer {

    // 使用JmsListener配置消费者监听的队列，其中text是接收到的消息
   /* @JmsListener(destination = "mytest.queue")
    public void receiveQueue(String text) {
        System.out.println("Consumer收到的报文为:"+text);
    }*/

    /*@JmsListener(destination = JmsConfig.TOPIC,containerFactory = "jmsListenerContainerTopic")
    public void onTopicMessage(String msg){
        System.out.println("接收到topic消息：{}"+msg);
    }*/

    @JmsListener(destination = JmsConfig.QUEUE,containerFactory = "jmsListenerContainerQueue")
    public void onQueueMessage(String msg){
        System.out.println("接收到queue消息：{}"+msg);
    }

    @JmsListener(destination = JmsConfig.TOPIC,containerFactory = "jmsListenerContainerTopic")
    public void onTopicMessage2(ObjectMessage msg){
        UserInfo userInfo = new UserInfo();
        try {
            userInfo = (UserInfo) msg.getObject();
            System.out.println("======================>"+userInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("接收到topic2消息：{}"+userInfo.toString());
    }
}
